class Solution1 {
    public static String multiply(String num1, String num2) {
        if (num1.equals("0") || num2.equals("0")) return "0";
        int m = num1.length(), n = num2.length();
        int[] tmp = new int[m + n - 1];
        for (int i = m - 1; i >= 0; i--) {
            for (int j = n - 1; j >= 0; j--) {
                int x = num1.charAt(i) - '0';
                int y = num2.charAt(j) - '0';
                tmp[n - 1 - i + m - 1 - j] += x * y;
            }
        }
        StringBuilder ret = new StringBuilder();
        // 处理进位
        int i = 0, t = 0;
        while (i < m + n - 1 || t != 0) {
            if (i < m + n - 1) t += tmp[i++];
            ret.append((char)((char)(t % 10) + '0'));
            t /= 10;
        }
        return ret.reverse().toString();
    }

    public static void main(String[] args) {
        System.out.println(multiply("9", "99"));
    }
}